package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 根据条件分页查询护理项目
     *
     * @param name     护理项目名称
     * @param pageNum  当前页数
     * @param pageSize 每页显示数量
     * @param status   状态
     * @return 分页查询结果
     */
    @GetMapping
    @ApiOperation("根据条件分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(
            @ApiParam(value = "护理项目名称",required = false) @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "当前页数", required = true) @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量", required = true) @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态",required = false) @RequestParam(value = "status", required = false) Integer status) {

        PageResponse<NursingProjectVo> page =
                nursingProjectService.selectByPage(name, pageNum, pageSize, status);
        return success(page);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDTO 护理项目DTO
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@ApiParam(value = "护理项目DTO") @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.insert(nursingProjectDTO);
        return success();
    }

    /**
     * 编辑护理项目
     *
     * @param nursingProjectDTO 护理项目DTO
     * @return 编辑结果
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult update(@ApiParam(value = "护理项目DTO") @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.update(nursingProjectDTO);
        return success();
    }

    /**
     * 启用和禁用护理项目
     *
     * @param id     护理项目ID
     * @param status 状态 (0: 禁用, 1: 启用)
     * @return 启用或禁用结果
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用和禁用护理项目")
    public ResponseResult enableAndDisable(
            @ApiParam(value = "护理项目ID") @PathVariable Long id,
            @ApiParam(value = "状态 (0: 禁用, 1: 启用)") @PathVariable Integer status) {
        nursingProjectService.enableAndDisable(id, status);
        return success();
    }

    /**
     * 根据id查询护理项目
     *
     * @param id 护理项目ID
     * @return 查询结果
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(
            @ApiParam(value = "护理项目ID") @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    /**
     * 根据id删除护理项目
     *
     * @param id 护理项目ID
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult deleteById(@ApiParam(value = "护理项目ID") @PathVariable("id") Long id) {
        nursingProjectService.deleteById(id);
        return success();
    }


    /**
     * 查询所有护理项目
     * @return
     */
    @ApiOperation("查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult getAll(){
        return success(nursingProjectService.getAll());
    }
}
